package com.wxy.service.impl;

import com.wxy.entity.*;
import com.wxy.service.EchartIndustryService;
import com.wxy.vo.EchartIndustryDataVo;
import com.wxy.vo.EchartIndustryLineVo;
import com.wxy.vo.EchartIndustryPieDataVo;
import com.wxy.vo.EchartIndustryPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class EchartIndustryImpl implements EchartIndustryService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public EchartIndustryLineVo getEchartDataByOverview(){
        List<MongoOverview> mongoOverviewList = mongoTemplate.findAll(MongoOverview.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoOverview mongoOverview : mongoOverviewList) {
            //加入名字
            nameList.add(mongoOverview.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoOverview.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoOverview.getZ1());
            data.add(mongoOverview.getZ2());
            data.add(mongoOverview.getZ3());
            data.add(mongoOverview.getZ4());
            data.add(mongoOverview.getZ5());
            data.add(mongoOverview.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByAgricultural() {
        List<MongoAgricultural> mongoAgriculturalList = mongoTemplate.findAll(MongoAgricultural.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoAgricultural mongoAgricultural: mongoAgriculturalList) {
            //加入名字
            nameList.add(mongoAgricultural.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoAgricultural.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoAgricultural.getZ1());
            data.add(mongoAgricultural.getZ2());
            data.add(mongoAgricultural.getZ3());
            data.add(mongoAgricultural.getZ4());
            data.add(mongoAgricultural.getZ5());
            data.add(mongoAgricultural.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByConstruction() {
        List<MongoConstruction> mongoConstructionList = mongoTemplate.findAll(MongoConstruction.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoConstruction mongoConstruction : mongoConstructionList) {
            //加入名字
            nameList.add(mongoConstruction.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoConstruction.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoConstruction.getZ1());
            data.add(mongoConstruction.getZ2());
            data.add(mongoConstruction.getZ3());
            data.add(mongoConstruction.getZ4());
            data.add(mongoConstruction.getZ5());
            data.add(mongoConstruction.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByEducation() {
        List<MongoEducation> mongoEducationList = mongoTemplate.findAll(MongoEducation.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoEducation mongoOverviewList : mongoEducationList) {
            //加入名字
            nameList.add(mongoOverviewList.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoOverviewList.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoOverviewList.getZ1());
            data.add(mongoOverviewList.getZ2());
            data.add(mongoOverviewList.getZ3());
            data.add(mongoOverviewList.getZ4());
            data.add(mongoOverviewList.getZ5());
            data.add(mongoOverviewList.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByFinancial() {
        List<MongoFinancial> mongoFinancialList = mongoTemplate.findAll(MongoFinancial.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoFinancial mongoFinancial : mongoFinancialList) {
            //加入名字
            nameList.add(mongoFinancial.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoFinancial.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoFinancial.getZ1());
            data.add(mongoFinancial.getZ2());
            data.add(mongoFinancial.getZ3());
            data.add(mongoFinancial.getZ4());
            data.add(mongoFinancial.getZ5());
            data.add(mongoFinancial.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByFishery() {
        List<MongoFishery> mongoFisheryList = mongoTemplate.findAll(MongoFishery.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoFishery mongoFishery : mongoFisheryList) {
            //加入名字
            nameList.add(mongoFishery.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoFishery.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoFishery.getZ1());
            data.add(mongoFishery.getZ2());
            data.add(mongoFishery.getZ3());
            data.add(mongoFishery.getZ4());
            data.add(mongoFishery.getZ5());
            data.add(mongoFishery.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByFood() {
        List<MongoFood> mongoFoodList = mongoTemplate.findAll(MongoFood.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoFood mongoFood : mongoFoodList) {
            //加入名字
            nameList.add(mongoFood.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoFood.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoFood.getZ1());
            data.add(mongoFood.getZ2());
            data.add(mongoFood.getZ3());
            data.add(mongoFood.getZ4());
            data.add(mongoFood.getZ5());
            data.add(mongoFood.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByForestry() {
        List<MongoForestry> mongoForestryList = mongoTemplate.findAll(MongoForestry.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoForestry mongoForestry : mongoForestryList) {
            //加入名字
            nameList.add(mongoForestry.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoForestry.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoForestry.getZ1());
            data.add(mongoForestry.getZ2());
            data.add(mongoForestry.getZ3());
            data.add(mongoForestry.getZ4());
            data.add(mongoForestry.getZ5());
            data.add(mongoForestry.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByHusbandry() {
        List<MongoHusbandry> mongoHusbandryList = mongoTemplate.findAll(MongoHusbandry.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoHusbandry mongoHusbandry : mongoHusbandryList) {
            //加入名字
            nameList.add(mongoHusbandry.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoHusbandry.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoHusbandry.getZ1());
            data.add(mongoHusbandry.getZ2());
            data.add(mongoHusbandry.getZ3());
            data.add(mongoHusbandry.getZ4());
            data.add(mongoHusbandry.getZ5());
            data.add(mongoHusbandry.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByManufacturing() {
        List<MongoManufacturing> mongoManufacturingList = mongoTemplate.findAll(MongoManufacturing.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoManufacturing mongoManufacturing : mongoManufacturingList) {
            //加入名字
            nameList.add(mongoManufacturing.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoManufacturing.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoManufacturing.getZ1());
            data.add(mongoManufacturing.getZ2());
            data.add(mongoManufacturing.getZ3());
            data.add(mongoManufacturing.getZ4());
            data.add(mongoManufacturing.getZ5());
            data.add(mongoManufacturing.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByMining() {
        List<MongoMining> mongoMiningList = mongoTemplate.findAll(MongoMining.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoMining mongoMining : mongoMiningList) {
            //加入名字
            nameList.add(mongoMining.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoMining.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoMining.getZ1());
            data.add(mongoMining.getZ2());
            data.add(mongoMining.getZ3());
            data.add(mongoMining.getZ4());
            data.add(mongoMining.getZ5());
            data.add(mongoMining.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByRetail() {
        List<MongoRetail> mongoOverviewList = mongoTemplate.findAll(MongoRetail.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoRetail mongoRetail : mongoOverviewList) {
            //加入名字
            nameList.add(mongoRetail.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoRetail.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoRetail.getZ1());
            data.add(mongoRetail.getZ2());
            data.add(mongoRetail.getZ3());
            data.add(mongoRetail.getZ4());
            data.add(mongoRetail.getZ5());
            data.add(mongoRetail.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    @Override
    public EchartIndustryLineVo getEchartDataByTechnology() {
        List<MongoTechnology> mongoOverviewList = mongoTemplate.findAll(MongoTechnology.class);
        EchartIndustryLineVo echartIndustryLineVo = new EchartIndustryLineVo();
        List<String> nameList = new ArrayList<>();
        List<EchartIndustryDataVo> dataVoList = new ArrayList<>();

        for (MongoTechnology mongoTechnology : mongoOverviewList) {
            //加入名字
            nameList.add(mongoTechnology.getName());
            //加入数据
            EchartIndustryDataVo echartIndustryDataVo = new EchartIndustryDataVo();
            echartIndustryDataVo.setType("line");
            echartIndustryDataVo.setName(mongoTechnology.getName());
            //data
            List<String> data = new ArrayList<>();
            data.add(mongoTechnology.getZ1());
            data.add(mongoTechnology.getZ2());
            data.add(mongoTechnology.getZ3());
            data.add(mongoTechnology.getZ4());
            data.add(mongoTechnology.getZ5());
            data.add(mongoTechnology.getZ6());
            echartIndustryDataVo.setData(data);
            //塞入容器
            dataVoList.add(echartIndustryDataVo);
        }
        echartIndustryLineVo.setName(nameList);
        echartIndustryLineVo.setValue(dataVoList);
        return echartIndustryLineVo;
    }

    //pie图
    @Override
    public EchartIndustryPieVo getEchartDataByFirst() {
        List<MongoFirst> mongoFirstList =  mongoTemplate.findAll(MongoFirst.class);
        EchartIndustryPieVo echartIndustryPieVo = new EchartIndustryPieVo();
        List<EchartIndustryPieDataVo> industryPieDataVoList = new ArrayList<>();
        for (MongoFirst mongoFirst : mongoFirstList) {
            EchartIndustryPieDataVo echartIndustryPieDataVo = new EchartIndustryPieDataVo();
            echartIndustryPieDataVo.setValue(Integer.valueOf(mongoFirst.getAcc()));
            echartIndustryPieDataVo.setName(mongoFirst.getName());
            industryPieDataVoList.add(echartIndustryPieDataVo);
        }
        echartIndustryPieVo.setValue(industryPieDataVoList);
        return echartIndustryPieVo;
    }

    @Override
    public EchartIndustryPieVo getEchartDataByIndustryTotal() {
        List<MongoIndustryTotal> mongoIndustryTotalList =  mongoTemplate.findAll(MongoIndustryTotal.class);
        EchartIndustryPieVo echartIndustryPieVo = new EchartIndustryPieVo();
        List<EchartIndustryPieDataVo> industryPieDataVoList = new ArrayList<>();
        for (MongoIndustryTotal mongoIndustryTotal : mongoIndustryTotalList) {
            EchartIndustryPieDataVo echartIndustryPieDataVo = new EchartIndustryPieDataVo();
            echartIndustryPieDataVo.setValue(Integer.valueOf(mongoIndustryTotal.getAcc()));
            echartIndustryPieDataVo.setName(mongoIndustryTotal.getName());
            industryPieDataVoList.add(echartIndustryPieDataVo);
        }
        echartIndustryPieVo.setValue(industryPieDataVoList);
        return echartIndustryPieVo;
    }

    @Override
    public EchartIndustryPieVo getEchartDataBySecond() {
        List<MongoSecond> mongoSecondList =  mongoTemplate.findAll(MongoSecond.class);
        EchartIndustryPieVo echartIndustryPieVo = new EchartIndustryPieVo();
        List<EchartIndustryPieDataVo> industryPieDataVoList = new ArrayList<>();
        for (MongoSecond mongoSecond : mongoSecondList) {
            EchartIndustryPieDataVo echartIndustryPieDataVo = new EchartIndustryPieDataVo();
            echartIndustryPieDataVo.setValue(Integer.valueOf(mongoSecond.getAcc()));
            echartIndustryPieDataVo.setName(mongoSecond.getName());
            industryPieDataVoList.add(echartIndustryPieDataVo);
        }
        echartIndustryPieVo.setValue(industryPieDataVoList);
        return echartIndustryPieVo;
    }

    @Override
    public EchartIndustryPieVo getEchartDataByThird() {
        List<MongoThird> mongoThirdList =  mongoTemplate.findAll(MongoThird.class);
        EchartIndustryPieVo echartIndustryPieVo = new EchartIndustryPieVo();
        List<EchartIndustryPieDataVo> industryPieDataVoList = new ArrayList<>();
        for (MongoThird mongoThird : mongoThirdList) {
            EchartIndustryPieDataVo echartIndustryPieDataVo = new EchartIndustryPieDataVo();
            echartIndustryPieDataVo.setValue(Integer.valueOf(mongoThird.getAcc()));
            echartIndustryPieDataVo.setName(mongoThird.getName());
            industryPieDataVoList.add(echartIndustryPieDataVo);
        }
        echartIndustryPieVo.setValue(industryPieDataVoList);
        return echartIndustryPieVo;
    }
}
